//
//  CHBNavigationViewController.swift
//  weibo.chb
//
//  Created by 褚红彪 on 16/1/21.
//  Copyright © 2016年 chuhongbiao. All rights reserved.
//

import UIKit

class CHBNavigationViewController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        //解决自定义返回按钮，返回手势失效的问题
        self.interactivePopGestureRecognizer?.delegate = self
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        if childViewControllers.count != 0{
            var title = "返回"
            if childViewControllers.count == 1{
                title = childViewControllers.first?.title ?? title
            }
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: "navigationbar_back_withtext", title: title, target: self, action: "popViewControllerAnimated:")
            viewController.hidesBottomBarWhenPushed = true
        }
        //print("push")
        super.pushViewController(viewController, animated: animated)
    }
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        //判断如果此时只有一个根控制器则手势失效，如果不止根控制器手势可以用，这样就解决了对根控制器使用边缘手势PUSH不过去的BUG
        return childViewControllers.count != 1
    }
}
